using System.Collections.Specialized;
using System.Windows.Forms;

namespace DirSearch
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void label2_Click(object sender, EventArgs e)
        {

        }
        StringCollection SearchFiles(string directory, string[] keywords)
        {
            var resultPaths = new StringCollection();
            try
            {
                foreach (string file in Directory.GetFiles(directory, "*", SearchOption.AllDirectories))
                {
                    foreach (string keyword in keywords)
                    {
                        if (Path.GetFileName(file).Contains(keyword))
                        {
                            resultPaths.Add(file);
                            break;
                        }
                    }
                }
            }
            catch (Exception ex)
            {

            }
            return resultPaths;
        }

        private void button2_Click(object sender, EventArgs e)
        {
            StringCollection strings = SearchFiles(textBox1.Text, textBox2.Text.Split(","));
            listView1.Items.Clear();
            foreach (string? file in strings)
            {
                listView1.Items.Add(file);
            }
        }

        private void button3_Click(object sender, EventArgs e)
        {
            StringCollection filePaths = new StringCollection();
            foreach (ListViewItem listViewItem in listView1.SelectedItems){
                filePaths.Add(listViewItem.Text);
            }
            if(filePaths.Count > 0)
            {
                Clipboard.SetFileDropList(filePaths);
            }
            
        }
    }
}
